Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow configuring relay-proxy request log verbosity #1946

Merged
merged 24 commits into from
Jun 11, 2024

Conversation

fals
Copy link
Contributor

@fals fals commented May 31, 2024

Description

TL;DR;
We are using the relay-proxy for a while in our system and we noticed that every request to relay proxy is recorded as log with level=info. Currently this log became a problem, because we generate 1.8 million request every 5 min to relay-proxy. The amount of logs injected in increase as consequence storage and cost.

This PR implements configuring the verbosity of relay-proxy, allowing you to log more if needed, or only errors.

Checklist

  • I have tested this code
  • I have added unit test to cover this code
  • I have updated the documentation (README.md and /website/docs)
  • I have followed the contributing guide

Copy link

netlify bot commented May 31, 2024

Deploy Preview for go-feature-flag-doc-preview ready!

Name Link
🔨 Latest commit 0054edf
🔍 Latest deploy log https://app.netlify.com/sites/go-feature-flag-doc-preview/deploys/6668aaede75ecf0008e3e90f
😎 Deploy Preview https://deploy-preview-1946--go-feature-flag-doc-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor Author

@fals fals left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow select verbosity of relay proxy request logging

@fals fals changed the title feature: allow configuring relay-proxy request log verbosity feat: allow configuring relay-proxy request log verbosity Jun 3, 2024
Copy link
Owner

@thomaspoignant thomaspoignant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @fals,
thanks a lot for this PR and I think you are right but we should probably be better in log management in general.

Instead of the VerboseRequestLogging I would prefer to have a property called LogLevel to set the level of the logs we want for the application.
The levels should be the classic ones debug, info, warn, error.

By setting this new option, we can also maybe deprecate the debug that is a bit too trivial here.

cmd/relayproxy/api/middleware/zap.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 74.46809% with 12 lines in your changes missing coverage. Please review.

Project coverage is 86.88%. Comparing base (2c71961) to head (0054edf).

Files Patch % Lines
cmd/relayproxy/main.go 0.00% 9 Missing ⚠️
cmd/editor/main.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1946      +/-   ##
==========================================
+ Coverage   86.81%   86.88%   +0.07%     
==========================================
  Files          98       98              
  Lines        3526     3553      +27     
==========================================
+ Hits         3061     3087      +26     
- Misses        357      358       +1     
  Partials      108      108              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@thomaspoignant thomaspoignant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the time it took for me to review it.
I added some comments about:

  • the removal of the debug option.
  • the way you init zap.
  • the name of the option that is not using camelcase in the config file.

Despite that it looks super good 👍

cmd/relayproxy/config/config.go Outdated Show resolved Hide resolved
cmd/relayproxy/testdata/config/valid-file.json Outdated Show resolved Hide resolved
cmd/relayproxy/api/middleware/zap.go Show resolved Hide resolved
cmd/relayproxy/config/config.go Outdated Show resolved Hide resolved
cmd/relayproxy/config/config.go Show resolved Hide resolved
cmd/relayproxy/testdata/config/valid-file.toml Outdated Show resolved Hide resolved
cmd/relayproxy/log/logger.go Outdated Show resolved Hide resolved
@fals
Copy link
Contributor Author

fals commented Jun 10, 2024

Sorry for the time it took for me to review it. I added some comments about:

  • the removal of the debug option.
  • the way you init zap.
  • the name of the option that is not using camelcase in the config file.

Despite that it looks super good 👍

@fals fals closed this Jun 10, 2024
@fals fals reopened this Jun 10, 2024
@@ -48,37 +48,40 @@ func main() {
_ = f.Parse(os.Args[1:])

// Init logger
zapLog := log.InitLogger()
defer func() { _ = zapLog.Sync() }()
logger := log.InitLogger()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaspoignant any tip to satisfy this coverage? The test for main is empty, just a dummy test there, and all new code I introduced is flagged, so I believe I have to find where exactly you test this cases. Could you guide me?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the time I don't test the main function.
So I guess this is not really a problem here.

Copy link
Contributor Author

@fals fals Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaspoignant let me know then what else needs to change to push this forward. The codecoverage isn't passing, that's why I asked the question.

Copy link
Owner

@thomaspoignant thomaspoignant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have spotted 2 minor things and I have pushed 1 more commit.
I will merge the PR.

Thanks a lot @fals for your contribution, this will be available in the next version of GO Feature Flag.
To continue improving the logging of GOFF I have also opened this PR #1955 that will support levelled log inside the core go module of GOFF.

Comment on lines 123 to 128
if proxyConf.Debug && proxyConf.LogLevel == "" {
log.Warn(
"Option Debug that you are using in your configuration file is deprecated" +
"and will be removed in future versions." +
"Please use logLevel: debug to continue to run the relay-proxy with debug logs.")
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxyConf.LogLevel == "" will never be true because you have a default value.

Suggested change
if proxyConf.Debug && proxyConf.LogLevel == "" {
log.Warn(
"Option Debug that you are using in your configuration file is deprecated" +
"and will be removed in future versions." +
"Please use logLevel: debug to continue to run the relay-proxy with debug logs.")
}
if proxyConf.Debug {
log.Warn(
"Option Debug that you are using in your configuration file is deprecated " +
"and will be removed in future versions." +
"Please use logLevel: debug to continue to run the relay-proxy with debug logs.")
}

if c == nil {
return false
}
return c.LogLevel == "debug" || c.Debug
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking in lowercase to be ready for any configuration string.

Suggested change
return c.LogLevel == "debug" || c.Debug
return strings.ToLower(c.LogLevel) == "debug" || c.Debug

Copy link

sonarcloud bot commented Jun 11, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@thomaspoignant thomaspoignant merged commit a2e12be into thomaspoignant:main Jun 11, 2024
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants